package fenetre;


public class Type {

	private String mLibelle;
	private int mCode;
	private String mClasse;
	private String mNom;
	private Integer mWidth;
	private Integer mHeight;

	public Type(int aI, int aI2) {
		mCode = Constante.TYPE_BT;
		getLibelle(mCode);
		getClasse(mCode);
		mWidth = aI;
		mHeight = aI2;
	}
	
	public Type(int aCode) {
		mCode = aCode;
		getLibelle(mCode);
		getClasse(mCode);
	}

	private void getClasse(int aCode) {
		if(aCode == Constante.TYPE_BT){
			mClasse = Constante.CLASSE_BT;
		}
		if(aCode == Constante.TYPE_COMBO){
			mClasse = Constante.CLASSE_COMBO;
		}
		if(aCode == Constante.TYPE_TXT){
			mClasse = Constante.CLASSE_TXT;
		}
		if(aCode == Constante.TYPE_LABEL){
			mClasse = Constante.CLASSE_LABEL;
		}
		if(aCode == Constante.TYPE_PANEL){
			mClasse = Constante.CLASSE_PANEL;
		}
		
	}

	private void getLibelle(int aCode) {
		if(aCode == Constante.TYPE_BT){
			mLibelle = Constante.LIBELLE_BT;
		}
		if(aCode == Constante.TYPE_COMBO){
			mLibelle = Constante.LIBELLE_COMBO;
		}
		if(aCode == Constante.TYPE_TXT){
			mLibelle = Constante.LIBELLE_TXT;
		}
		if(aCode == Constante.TYPE_LABEL){
			mLibelle = Constante.LIBELLE_LABEL;
		}
		if(aCode == Constante.TYPE_PANEL){
			mLibelle = Constante.LIBELLE_PANEL;
		}
	}

	@Override
	public String toString() {
		return mLibelle;
	}

	public int getCode() {
		return mCode;
	}

	public String getClasse() {
		return mClasse;
	}
	
	public void setClasse(String aClasse) {
		mClasse = aClasse;
	}

	public static Type newInstanceTypeClass(String aComposantClasse, String aNom,int aWidth,int aHeight) {
		Type lType = new Type(aWidth,aHeight);
		lType.setNom(aNom);
		lType.setWidth(aWidth);
		lType.setHeight(aHeight);
		int lIndex;
		
		if(aComposantClasse.equals(Constante.CLASSE_BT)){
			lIndex = Constante.TYPE_BT;
		} else if(aComposantClasse.equals(Constante.CLASSE_BT)){
			lIndex = Constante.TYPE_COMBO;
		} else if(aComposantClasse.equals(Constante.CLASSE_TXT)){
			lIndex = Constante.TYPE_TXT;
		} else if(aComposantClasse.equals(Constante.CLASSE_LABEL)){
			lIndex = Constante.TYPE_LABEL;
		} else if(aComposantClasse.equals(Constante.CLASSE_PANEL)){
			lIndex = Constante.TYPE_PANEL;
		} else {
			lIndex = Constante.TYPE_BT;
		}
		lType.setCode(lIndex);
		lType.getLibelle(lIndex);
		lType.getClasse(lIndex);
		return lType;
	}

	private void setNom(String aNom) {
		mNom = aNom;
	}

	private void setCode(int aIndex) {
		mCode = aIndex;
	}

	public String getNom() {
		return mNom;
	}

	public Integer getHeight() {
		return mHeight;
	}

	public Integer getWidth() {
		return mWidth;
	}

	public void setWidth(int aWidth) {
		mWidth = aWidth;
	}

	public void setHeight(int aHeight) {
		mHeight = aHeight;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + mCode;
		return result;
	}

	public boolean equals(Type aType) {
		if(aType.getCode() == mCode){
			return true;
		}
		return false;
	}
	
	

}
